package com.mangofactory.flapper.parsley.lifecycle
{
	import org.as3commons.bytecode.proxy.ProxyFactory;
	import org.spicefactory.parsley.core.lifecycle.ManagedObject;
	import org.spicefactory.parsley.core.registry.ObjectInstantiator;
	
	/**
	 * Implementation of the Parsley ObjectInstantiator interface
	 * for creating the Proxy objects within the DI container.
	 * */
	public class ProxyInstantiator implements ObjectInstantiator
	{
		private var proxyFactory:ProxyFactory
		public function ProxyInstantiator(proxyFactory:ProxyFactory)
		{
			this.proxyFactory = proxyFactory;
		}
		
		public function instantiate(target:ManagedObject):Object
		{
			// TODO : Add support for paramaterized constructors
			var instance:Object = proxyFactory.createProxy(target.definition.type.getClass());
			return instance;
		}
	}
}